<?php

/**
 * NOTICE OF LICENSE
 *
 * THIS SOURCE FILE IS PART OF EVEBIT'S PRIVATE PROJECT.
 * 
 * DO NOT USE THIS FILE IN OTHER PLACE.
 *
 * @category    ChinaWanderer
 * @package     Backend
 * @subpackage  Model
 * @author      Chen Qiao <chen.qiao@evebit.com>
 * @version     $$Id: Role.php 1427 2011-06-27 06:54:49Z chen.hao $$
 * @copyright   Copyright (c) 2011 Evebit Inc. China (http://www.evebit.com)
 */

/**
 * Model Role for backend
 * 
 * view,delete,search,sort,edit role
 * 
 * @package     Backend
 * @subpackage  Model
 * @author      chen qiao <chen.qiao@evebit.com>
 * @version     $$Id: Role.php 1427 2011-06-27 06:54:49Z chen.hao $$
 */

class Default_Model_Entity_Role extends Evebit_Model_Abstract {
	
	function getRoleTree() {
		$resource = new Default_Model_Entity_Resource ();
		$items = $resource->getCollection ()->getItems ();
		$tree = array ();
		foreach ( $items as $item ) {
			if (! array_key_exists ( $item->scope, $tree )) {
				$tree [$item->scope] = array ();
			}
			if (! array_key_exists ( $item->module, $tree [$item->scope] )) {
				$tree [$item->scope] [$item->module] = array ();
			}
			if (! array_key_exists ( $item->controller, $tree [$item->scope] [$item->module] )) {
				$tree [$item->scope] [$item->module] [$item->controller] = array ();
			}
			$tree [$item->scope] [$item->module] [$item->controller] [$item->action] = array ();
			if ($item->getParams () != "") {
				$params = explode ( ",", $item->getParams () );
				array_push ( $tree [$item->scope] [$item->module] [$item->controller] [$item->action], $params );
			}
		}
		return $tree;
	}
}
